package com.wuyan.locationdog.adapter

import android.graphics.Color
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.LayoutRes
import com.arcsoft.commonbase.bean.DeviceBeanContent
import com.arcsoft.commonbase.ext.gone
import com.arcsoft.commonbase.ext.loadImageCircleCar
import com.arcsoft.commonbase.ext.radius
import com.arcsoft.commonbase.ext.visible
import com.arcsoft.commonbase.ext.visibleOrGone
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.wuyan.locationdog.R
import com.wuyan.locationdog.help.DeviceHelp


class DeviceListAdapter(@LayoutRes layoutResId: Int, data: MutableList<DeviceBeanContent>?) :
    BaseQuickAdapter<DeviceBeanContent, BaseViewHolder>(layoutResId, data) {

    var showCheckBtn: Boolean = false

    override fun convert(holder: BaseViewHolder, item: DeviceBeanContent) {
        holder.apply {
            val imageView = getView<ImageView>(R.id.ivCheck)
            if (showCheckBtn) {
                imageView.visible()
            } else {
                imageView.gone()
            }

            if (item.isSelect) {
                imageView.setImageResource(R.mipmap.alarm_checked)
            } else {
                imageView.setImageResource(R.mipmap.alarm_unchecked)
            }

            //绑定类型1绑定2共享
            getView<ImageView>(R.id.bindType).visibleOrGone(item.deviceDetailVO.bindType != 1)
            getView<ImageView>(R.id.dogImg).loadImageCircleCar(item.dog?.dogImg)

            getView<TextView>(R.id.deviceName).text = DeviceHelp.getDeviceName(item)
            if (item.dog != null) {
                getView<ImageView>(R.id.isBindDevice).setImageResource(R.mipmap.bind_dog_yes)
            } else {
                getView<ImageView>(R.id.isBindDevice).setImageResource(R.mipmap.bind_dog_no)
            }
            getView<TextView>(R.id.deviceId).text = "设备ID：" + item.imei
            val compositeStatusDesc = getView<TextView>(R.id.compositeStatusDesc)
            compositeStatusDesc.text = item.compositeStatusDesc
            val dot = getView<View>(R.id.dot)
            dot.radius(2.5F)
            when (item.compositeStatus) {
                1 -> {
                    compositeStatusDesc.setTextColor(Color.parseColor("#6E4DF3"))
                    dot.setBackgroundColor(Color.parseColor("#6E4DF3"))
                }

                2 -> {
                    compositeStatusDesc.setTextColor(Color.parseColor("#A5A5A5"))
                    dot.setBackgroundColor(Color.parseColor("#A5A5A5"))

                }

                3 -> {
                    compositeStatusDesc.setTextColor(Color.parseColor("#666666"))
                    dot.setBackgroundColor(Color.parseColor("#666666"))

                }

                else -> {
                    compositeStatusDesc.setTextColor(Color.parseColor("#5AE4D9"))
                    dot.setBackgroundColor(Color.parseColor("#5AE4D9"))

                }
            }

        }
    }
}


